package lab03.test07;
import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.io.*;
public class Test07 {
    public static void main(String[] args)  {
        String path="D:\\book.zip";
        File file=null;
        ZipInputStream zipInputStream=null;//压缩文件的字节输入流
        InputStream inputStream=null;
        FileOutputStream fileOutputStream=null;
        ZipEntry zipEntry=null;//Entry进入,入口的意思,相当于入口
        try {
            ZipFile zipFile=new ZipFile(path);
            zipInputStream=new ZipInputStream(new FileInputStream(path));
//zip的这个输入流是为了读取名字
        while(( zipEntry=zipInputStream.getNextEntry())!=null){

                System.out.println("压缩文件名为 "+zipEntry.getName());//读取压缩文件里面的每个文件名
                file=new File("D:\\book"+File.separator+zipEntry.getName());
                      //File.separator是加上斜线，相当于“\\”
                file.createNewFile();

inputStream=zipFile.getInputStream(zipEntry);//这个输入流是为了读取入口文件
fileOutputStream=new FileOutputStream(file);//实例化输出流,outFile是写入的文件路径
int ch=0;
                while ((ch=inputStream.read())!=-1){
                    fileOutputStream.write(ch);

                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
